[[fetch]]
from = "https://raw.githubusercontent.com/code32123/CustomLanguage/main/"
files = ["main.py"]
import js
import json
from pyodide.ffi import to_js
newExprBox = Element("newExpression")
#lB = Element("lB")
#rB = Element("rB")
page = 0
from main import main
AST = main("print(\"Math:\", (4*var+1)*2);", silent=True)
#AST.print()
def pageHome():
global page
page = 0
reloadInterface()
def pageEnd():
global page, debuggingDump
page = len(debuggingDump)-1
reloadInterface()
def pageLeft():
global page
if page > 0:
page+= -1
reloadInterface()
def pageRight():
global page, debuggingDump
if page < len(debuggingDump)-1:
page+= 1
reloadInterface()
def reloadInterface():
#print(page)
#print(debuggingDump[page])
data = recursiveTree(debuggingDump[page], [], [0])
#print(data)
js.myTranslator(to_js(data))
#lB.disabled = page == 0
#rB.disabled = len(debuggingDump)-1
def encodePath(path):
return "-".join([str(x) for x in path])
def escape(name):
return name.replace('"', '"')
def getElementText(element):
name = escape(str(element["Name"]))
ttype = escape(str(element["Type"]))
maxC = " (" + str(element["MaxChildren"]) + ")"
if element["Type"] == "parenObject":
return ttype
return ((ttype + ":") if element["Type"] != None else "") + name
def recursiveTree(element, soFar, path, parent=None, dispParenLocked=False):
thisText = getElementText(element)
thisID = encodePath(path)
mchildren = element["MaxChildren"] if element["MaxChildren"] != -1 else ""
soFar.append({"key":thisID, "parent":parent, "DisplayText":thisText, "MaxChildren":mchildren, "locked":dispParenLocked})
for i, child in enumerate(element["Children"]):
childID = encodePath(path + [i])
if child["Type"] == "parenObject":
if child["Name"]:
dispParenLocked = True
soFar = recursiveTree(child, soFar, path + [i], parent=thisID, dispParenLocked=dispParenLocked)
return soFar
def inputNewExpression():
global debuggingDump, page
AST, debuggingDump = main(newExprBox.value, silent=True, outputDebugs=True)
page = 0
#page = len(debuggingDump)-1
reloadInterface()
inputNewExpression()